//获取当前时间戳 reutrn YYYY-MM-DD
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        //var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();

        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
        return currentdate;
    };
//传入一个  YYYYY-MM-DD  前推和后退数以天数
    function nextDayFnc(startTime,y,z){
        var startTime = startTime;
        var startTime2 = startTime.split("-");
        var year = parseInt(startTime2[0]);
        var month = parseInt(startTime2[1]);
        var day = parseInt(startTime2[2]);
        var myDate=new Date();
        var setYesDay =  parseInt(myDate.setFullYear(year,month-1,day));
        if(z==1){
            var yesterday = parseInt(setYesDay-86400000*y);     //加减天数改变这个毫秒数
        }else if(z==2){
            var yesterday = parseInt(setYesDay+86400000*y);      //z==1时为-  z==2时为+
        }
        var ds = new Date(yesterday);
        var oldYear=ds.getYear()+1900;
        var oldMonth = ds.getMonth()+1;
        if (oldMonth<10){
            oldMonth = "0"+oldMonth;
        }else{
            oldMonth = oldMonth;
        }
        var oldDay = ds.getDate();
        if(oldDay<10){
            oldDay = "0"+oldDay;
        }else{
            oldDay = oldDay;
        }
        var yesDay = oldYear+"-"+oldMonth+"-"+oldDay;
        return yesDay;
    };
//传入 YYYYY-MM-DD 转成 yyyy年mm月dd日
    function parseDate(date){
        var newDate = date.split("-");
        return newDate[0]+"年"+newDate[1]+"月"+newDate[2]+"日";
    }
    var date = new Date();
    var lastWeek = new Date(date.getTime() - 6 * 24 * 3600 * 1000);
    var lastTwo = new Date(date.getTime() - 13 * 24 * 3600 * 1000);
    var tody = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    lastWeek = lastWeek.getFullYear() + "-" + (lastWeek.getMonth() + 1) + "-" + lastWeek.getDate();
    lastTwo = lastTwo.getFullYear() + "-" + (lastTwo.getMonth() + 1) + "-" + lastTwo.getDate();
    var yesterday = nextDayFnc(getNowFormatDate(), 1, 1);
    // 借用nextDayFnc方法将XXXX-X-X转化成XXXX-0X-0X格式
    tody = nextDayFnc(tody,0,1);
    lastWeek = nextDayFnc(lastWeek,0,1);
    lastTwo = nextDayFnc(lastTwo,0,1);
    $(".tody_btn").html("今日："+parseDate(tody));
	$(".tody_day").html("今日："+parseDate(tody));
	$(".yesterday_day").html("昨日："+parseDate(yesterday));
	$(".lastWeek_day").html("最近7日："+parseDate(lastWeek)+" — "+parseDate(tody));
	$(".lastTwo_day").html("最近14日："+parseDate(lastTwo)+" — "+parseDate(tody));
	
	
//	时间
	var beginDate=tody;
	var endDate=tody;

//点击事件
function selectDate(d,obj){
	if(d == 1){
		beginDate=tody;
		endDate=tody;
		$(".tody_btn").html($(obj).find("a").html());
	}else if(d == 2){
		beginDate=yesterday;
		endDate=tody;
		$(".tody_btn").html($(obj).find("a").html());
	}else if(d == 3){
		beginDate=lastWeek;
		endDate=tody;
		$(".tody_btn").html($(obj).find("a").html());
	}else if(d == 4){
		beginDate=lastTwo;
		endDate=tody;
		$(".tody_btn").html($(obj).find("a").html());
	}else if(d == 5){
		var test1=$("#test1").val();
		var test2=$("#test2").val();
		if(!test1){
			layer.msg("请先选择时间");
			return false;
		}
		if(!test2){
			layer.msg("请先选择时间");
			return false;
		}
		beginDate=test1;
		endDate=test2;
		$(".tody_btn").html("时间为："+parseDate(test1)+" — "+parseDate(test2));
		$(".tody_btn").parent().removeClass("open");
	}
	p=1;
	tiaozhuan(p);
}


//获取交易类型
$('.jiaoyi_lx .jiaoyi_sx').on('click',function(){
	var dib = $(this).text();
	tradeType=$(this).find("a").attr('data-id');
	$('.jyshuxing').html(dib);
	p=1;
	tiaozhuan(p);
})

//财务记录列表
var p=1;
var tradeType='0';
var adverId='';
function tiaozhuan(p){	
	var pageSize=$('.ui-select-pagesize').val();
	var d={};
	d.page=p;
	d.pageSize=pageSize;
	d.createTime=beginDate;
	d.endTime=endDate;
	d.tradeType=tradeType;

	$.ajax({
		url: url + "/sys/fiTradeRecordCom/queryTradeRecord",
		type: 'POST',
		//		参数需转为字符串
		data: JSON.stringify(d),
		//		json跨域
		dataType: 'json',
		//		contentType类型为json
		contentType: "application/json",

		//		请求头加上X-Token 
		 beforeSend: function(XMLHttpRequest) {
			//		token 为页面所获取
			   
			XMLHttpRequest.setRequestHeader("X-Token", token); 
		},
		useDefaultXhrHeader: false,
		success: function(result) {
			if(result.code == '0') {
				var data=result.data.rows;
				var html="";
				for(var i in data){
					html += '<tr class="ng-scope"><td  class="ng-binding">'+data[i].createTime+'</td>';
					html += '<td  class="ng-binding">'+data[i].adComId+'</td><td  class="ng-binding">'+data[i].adComName+'</td>';
					if(data[i].tradeType == '0'){
						html += '<td  class="ng-binding">全部类型</td>';
					}else if(data[i].tradeType == '1'){
						html += '<td  class="ng-binding">Admin转入资金</td>';
					}else if(data[i].tradeType == '2'){
						html += '<td  class="ng-binding">Admin转出资金</td>';
					}else if(data[i].tradeType == '3'){
						html += '<td  class="ng-binding">广告公司充值</td>';
					}else if(data[i].tradeType == '4'){
						html += '<td  class="ng-binding">广告公司提现</td>';
					}else if(data[i].tradeType == '5'){
						html += '<td  class="ng-binding">竞价交易利润</td>';
					}else if(data[i].tradeType == '6'){
						html += '<td  class="ng-binding">保价保量利润</td>';
					}else if(data[i].tradeType == '7'){
						html += '<td  class="ng-binding">保价保量扣款</td>';
					}else if(data[i].tradeType == '8'){
						html += '<td  class="ng-binding">保价保量收入</td>';
					}				
					html += '<td  class="ng-binding">'+data[i].amount+'</td><td  class="ng-binding">'+data[i].operInstruct+'</td></tr>';
				}
				$(".record_list").html(html);
				var r=result.data.total;
					paging(p,pageSize,r);
			} else {
				isErr(result);
			}
		},
		err: function(err) {
			layer.msg("请求失败");
		}
		
	});
}
tiaozhuan(p);
